﻿using Abp.Application.Transactions;
using Abp.Dependency;
using Castle.Facilities.Logging;
using Castle.Windsor;

namespace Abp.Configurations
{
    /// <summary>ENode configuration class Autofac extensions.
    /// </summary>
    public static class ConfigurationExtensions
    {
       
        
        /// <summary>Use Autofac as the object container.
        /// </summary>
        /// <returns></returns>
        public static Configuration UseCastle(this Configuration configuration)
        {
            ObjectContainer.SetContainer(new CastleObjectContainer());
            return configuration;
        }

        /// <summary>Use Autofac as the object container.
        /// </summary>
        /// <returns></returns>
        public static Configuration UseCastle(this Configuration configuration, IWindsorContainer container)
        {
            ObjectContainer.SetContainer(new CastleObjectContainer(container));
            return configuration;
        }
        /// <summary>Use Log4Net as the logger.
        /// </summary>
        /// <returns></returns>
        public static Configuration UseLog4Net(this Configuration configuration)
        {
            return UseLog4Net(configuration, "log4net.config");
        }
        /// <summary>Use Log4Net as the logger.
        /// </summary>
        /// <returns></returns>
        public static Configuration UseLog4Net(this Configuration configuration, string configFile)
        {
           ((CastleObjectContainer) ObjectContainer.Current).Container.AddFacility<LoggingFacility>(f => f.UseLog4Net(configFile));
            return configuration;
        }
        /// <summary>
        /// 启用事务拦截
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static Configuration UseTransactionScope(this Configuration configuration)
        {
            TransactionInterceptorRegistrar.Initialize();
            return configuration;
        }


    }
}